import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 消息发送方式枚举 */
export enum MessageSendWayEnum {
  /** 内部消息 */
  Internal = 1,
  /** 邮件消息 */
  Email = 2,
  /** 第三方平台消息 */
  OAuth2 = 99,
}

/** 消息发送方式实体 */
export class MessageSendWayEntity {
  /** 消息发送方式 */
  MessageSendWay: MessageSendWayEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(messageSendWay: MessageSendWayEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.MessageSendWay = messageSendWay;
    this.Color = color;
    switch (messageSendWay) {
      case MessageSendWayEnum.Internal:
        // this.Display = '内部消息';
        this.Display = t('enum.messageSendWay.internal');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case MessageSendWayEnum.Email:
        // this.Display = '邮件消息';
        this.Display = t('enum.messageSendWay.email');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
      case MessageSendWayEnum.OAuth2:
        // this.Display = '第三方平台消息';
        this.Display = t('enum.messageSendWay.oAuth2');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
    }
  }
}

//#region 获取消息发送方式枚举架构
/**
 * 获取消息发送方式枚举架构
 */
export function getMessageSendWayEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: MessageSendWayEntity[] = [
    new MessageSendWayEntity(MessageSendWayEnum.Internal),
    new MessageSendWayEntity(MessageSendWayEnum.Email),
    new MessageSendWayEntity(MessageSendWayEnum.OAuth2),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.MessageSendWay as number,
      label: item.Display,
      value: item.MessageSendWay as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
